package com.nk.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.nk.system.beans.CriteriaBean;
import com.nk.system.beans.ProgramBean;
import com.nk.system.common.search.Search;
import com.nk.system.dao.ProgramCriteriaDao;
import com.nk.system.domain.ProgramCriteria;
import com.nk.system.service.CalculateService;

@Service("calculateService")
public class CalculateServiceImpl extends GenericServiceImpl<ProgramCriteria, Integer, ProgramCriteriaDao>  implements CalculateService{
	
	private Logger log = Logger.getLogger(AuthenticationServiceImpl.class);
	
	@Autowired
	public CalculateServiceImpl(ProgramCriteriaDao programCriteriaDao) {
		super(programCriteriaDao);
	}

	@Override
	public List<CriteriaBean> getCalcutale(ProgramBean major) {
		// TODO Auto-generated method stub
		
		List<CriteriaBean> criteriaList = new ArrayList<CriteriaBean>();
		
		try {
			Search search = new Search(ProgramCriteria.class);
			search.addFilterEqual("majorId", major.getId());
			search.addSortAsc("courseId");
			
			List<ProgramCriteria> programCriteriaList = dao.search(search);
			
			for(ProgramCriteria criteria:programCriteriaList) {
				CriteriaBean criteriaBean = new CriteriaBean();
				criteriaBean.setId(criteria.getId());
				criteriaBean.setMajorID(criteria.getMajorId());
				criteriaBean.setCourseID(criteria.getCourseId());
				criteriaBean.setWeight(criteria.getWeight());
				criteriaBean.setMinimum(criteria.getMinimum());
				
				criteriaList.add(criteriaBean);
			}
		}catch(Exception e) {
			log.error(e,e);
		}
		return criteriaList;
		
	}

	

}
